<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <style>
        hr{
            margin-top: 0;
        }
        h2{
            margin-bottom: 5px;
        }
        .banner {
            margin-bottom: 40px;
            font-size: 20px;
            margin-top:51px;
            text-align:left;
            position: relative;
            padding: 30px 0;
            color: #cdbfe3;
            text-shadow: 0 1px 0 rgba(0,0,0,.1);
            background-color: #6f5499;
            background-image: -webkit-gradient(linear,left top,left bottom,from(#563d7c),to(#6f5499));
            background-image: -webkit-linear-gradient(top,#563d7c 0,#6f5499 100%);
            background-image: -o-linear-gradient(top,#563d7c 0,#6f5499 100%);
            background-image: linear-gradient(to bottom,#563d7c 0,#6f5499 100%);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#563d7c', endColorstr='#6F5499', GradientType=0);
            background-repeat: repeat-x
        }
        .header{
            margin-bottom: 0;
            background-color: #fff;
            border-bottom: #6f5499 1px solid;
        }
        .banner h1 {
            margin-top: 0;
            color: #fff
        }

        .banner p {
            margin-bottom: 0;
            font-weight: 300;
            line-height: 1.4
        }

        .banner .container {
            position: relative
        }
        .swatch {
            position: relative;
            margin-bottom: 20px;
            cursor: pointer;
            height: 100px;
            padding: 0;

            border-radius: 3px;
        }
        .brand-success {
            background-color: #5cb85c
        }
        .swatch .short {
            color: rgba(251,251,251,0.5);
            font-size: 1.9em;
            float: right;
            margin-right: 7px;
            margin-top: 5px;
            font-weight: bold;

        }

        .swatch .title {
            color: #fff;
            background-color: rgba(74, 140, 74, 0.39);
            height: 24px;
            line-height: 24px;
            position: absolute;
            bottom: 0;
            width: 100%;
            text-align: center;
        }
        .label{
            margin-top: 3px;
            display: inline-block;
            width: 58px !important;
        }

        .dropdown-menu{
            height: 300px;
            overflow-x: hidden;
            overflow-y: scroll;
        }
        ul,li{
            list-style: none;
        }
        .reading{
            padding-left: 0;
        }
        .reading li{
            font-size:1.5em;
            border-bottom: 1px dashed #f0f0f0;
            overflow: hidden;
            padding: 10px 0px 0px 0px;
        }
        .reading span{
            float:left;
        }
        .reading p{
            cursor: pointer;
            color:#666;
            padding-left: 66px;
        }

        .quotes{
            font-weight: bold;
            color:#1b6d85 !important;
            font-style: italic;

        }
        .footer {
            padding-top: 20px;
            padding-bottom: 20px;
            margin-top: 20px;
            color: #767676;
            text-align: center;
            border-top: 1px solid #e5e5e5
        }

        .footer-links {
            padding-left: 0;
            margin-top: 20px
        }

        .footer-links li {
            display: inline;
            padding: 0 2px
        }

        .footer-links li:first-child {
            padding-left: 0
        }
    </style>
</head>
<body>
<header class="header navbar navbar-static-top navbar-fixed-top" id="top">
    <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#bs-navbar"
                    aria-controls="bs-navbar" aria-expanded="false">
                <span class="sr-only">切换导航</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>

            <a href="javascript:Home()" class="navbar-brand">Bible</a>
        </div>
        <nav class="collapse navbar-collapse">

            <ul class="nav navbar-nav">
                <li class="dropdown">
                    <a id="drop1" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                       aria-haspopup="true" aria-expanded="false">
                        旧约
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="drop1">
                        <li v-for="book in Directories.OldTestaments.book">
                            <a href="javascript:GetBook('{{book.cfn}}')">{{book.b}}</a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a id="drop2" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                       aria-haspopup="true" aria-expanded="false">
                        新约
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="drop1">
                        <li v-for="book in Directories.NewTestaments.book">
                            <a href="javascript:GetBook('{{book.cfn}}')">{{book.b}}</a>
                        </li>
                    </ul>
                </li>

            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li id="fat-menu" class="dropdown">
                    <a id="drop3" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                       aria-haspopup="true" aria-expanded="false">
                        章节选择
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="drop3">
                        <li v-for="context in Chapters.verses"><a href="javascript:ChangeVerse({{$index}})">第
                            {{context.c}} 章</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="javascript:Home()">返回首页</a></li>
                    </ul>
                </li>
            </ul>
        </nav>
    </div>
</header>
<div class="banner">
    <div class="container">
        <h1>神</h1>
        <p>是我们的避难所，是我们的力量，是我们在患难中随时的帮助。</p>
        <p style="text-align: right; font-style:italic">--诗篇46:1</p>
    </div>
</div>
<div class="container">
<div class="container-fluid">

    <div id="divDirectories" v-if="Reading">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <h2><span class="glyphicon glyphicon-book" aria-hidden="true"></span> 旧约</h2>
                <hr />
            </div>

            <div class="col-xs-6 col-sm-6 col-md-3"  v-for="book in Directories.OldTestaments.book" onclick="GetBook('{{book.cfn}}')">
                <div class="{{$index | brand}}">
                    <div class="short">{{book.a}}</div>
                    <div class="title">{{book.b}}</div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <h2><span class="glyphicon glyphicon-book" aria-hidden="true"></span> 新约</h2>
                <hr />
            </div>

        <div class="col-xs-6 col-sm-6 col-md-3"  v-for="book in Directories.NewTestaments.book" onclick="GetBook('{{book.cfn}}')">
            <div class="{{$index | brand}}">
                <div class="short">{{book.a}}</div>
                <div class="title">{{book.b}}</div>
            </div>
        </div>
        </div>
    </div>


    <div class="row" id="divVerses" v-else>
        <h3 class="page-header">
            <span class="glyphicon glyphicon-book"></span> {{Chapters.book}} / 第 {{Verses.c}} 章
        </h3>
        <ul class="reading">
            <li v-for="text in Verses.text">
                <span class="label label-success">{{Verses.c}}:{{text.v}}</span>
                <p onclick="ChangeStyle(this)">{{text.text | trim}}</p>
            </li>
        </ul>

        <div style="float: left">
            <button class="btn btn-success" onclick="Pre()">上一节</button>
        </div>
        <div style="float: right">
            <button class="btn btn-success" onclick="Next()">下一节</button>
        </div>
    </div>
</div>
</div>

<footer class="footer">
    <div class="container-fluid">

        <ul class="footer-links text-muted">
            <li>当前版本： v1.0.0</li>
            <li>&middot;</li>
            <li>
                <a href="http://www.jidujiao.com/">基督教中文网</a>
            </li>
            <li>&middot;</li>
            <li>
                <a href="http://www.yisa.me/">以撤科技</a>
            </li>
            <li>&middot;</li>
            <li>
                <a href="http://bible.sdacn.org/">圣经资源网</a>
            </li>
            <li>&middot;</li>
            <li>
                <a href="mail:jasstion@gmail.com">联系我</a>
            </li>
        </ul>
    </div>
</footer>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/vue.min.js"></script>
<script>
    var brands = ['brand-primary', 'brand-success', 'brand-info', 'brand-warning', 'brand-danger'];
    var books = {
        Directories: {OldTestaments: {}, NewTestaments: {}},
        Chapters: {},
        Verses: {},
        VerseIndex:0,
        Reading:true
    };
    var vm = new Vue({
        el: 'body',
        data: books
    });
    Vue.filter('brand', function (index) {
        index = index % 5;
        return 'swatch ' + brands[1];
    });
    Vue.filter('trim',function(str){
        return str.replace(/(^\s*)|(\s*$)/g, '');
    });
    function GetData(dataUrl, callBack) {
        $.ajax({
            type: "get",
            url: dataUrl,
            async: true,
            success: function (data) {
                callBack(data);
            },
            error: function (err) {
                console.log("获取数据出错：" + err);
            }
        });
    }
    function getDirectories(dataUrl) {

        GetData(dataUrl, function (data) {
            books.Directories.OldTestaments = data.books.Testament[0];
            books.Directories.NewTestaments = data.books.Testament[1];
        });
    }
    function GetBook(cfn) {
        cfn = "books/" + cfn + ".json";
        GetData(cfn, function (data) {
            books.Chapters = data.chaptersXml;
            books.Verses = data.chaptersXml.verses[0];
            books.Reading=false;
            //vm.Chapters=data.chaptersXml;
        });
    }
    function ChangeVerse(index) {
        books.VerseIndex=index;
        books.Verses = books.Chapters.verses[index];
        $('html,body').animate({scrollTop:$('#divVerses').offset().top},1000);
    }
    function ChangeStyle(obj){
        $(obj).toggleClass('quotes');
    }
    function Next(){
        var len=books.Chapters.verses.length;
        if(books.VerseIndex<len){
            books.VerseIndex+=1;
        }else{
            books.VerseIndex=len-1;
        }
        ChangeVerse(books.VerseIndex);
    }
    function Pre(){
        if(books.VerseIndex>0){
            books.VerseIndex-=1;
        }else{
            books.VerseIndex=0;
        }
        ChangeVerse(books.VerseIndex);
    }
    function Home(){
        books.Reading=true;
    }
    $(function () {
        getDirectories("books/books.xml.json");

        $('html,body').dblclick(function(){
            $('html,body').animate({scrollTop:$('#top').offset().top},1000);
        })

    });
</script>

</body>
</html>